package top.toptimus.dto.material;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.toptimus.util.DateTimeUtil;
import top.toptimus.util.ValueUtil;

import java.text.DecimalFormat;
import java.util.Map;

/**
 * 面料信息
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MateriaDetaillDTO {

    private String id;
    private String fabric;
    private String quantity;
    private String inout_type;
    private String create_date;
    private String code;
    private String price;
    private String totalQuanlity;
    private String orderId;
    private String orderNo;

    public MateriaDetaillDTO(Map<String, Object> stringObjectMap) {
        try {
            this.id = stringObjectMap.containsKey("id") ? stringObjectMap.get("id").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.fabric = stringObjectMap.containsKey("fabric") ? stringObjectMap.get("fabric").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.quantity = stringObjectMap.containsKey("quantity") ? stringObjectMap.get("quantity").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.inout_type = stringObjectMap.containsKey("inout_type") ? stringObjectMap.get("inout_type").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.create_date =
                    DateTimeUtil.convertToDate(
                            DateTimeUtil.strToDateLong(
                                    stringObjectMap.containsKey("create_date") ? stringObjectMap.get("create_date").toString() : ""
                            )
                    );

        } catch (Exception ignored) {
        }
        try {
            this.code = stringObjectMap.containsKey("code") ? stringObjectMap.get("code").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.orderId = stringObjectMap.containsKey("order_id") ? stringObjectMap.get("order_id").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.orderNo = stringObjectMap.containsKey("order_no") ? stringObjectMap.get("order_no").toString() : "";
        } catch (Exception ignored) {
        }
        try {
            this.price =
                    new DecimalFormat(".00").format(ValueUtil.DoubleNullValue(
                            stringObjectMap.containsKey("price") ? stringObjectMap.get("price").toString() : ""
                    ));
        } catch (Exception ignored) {
        }
        try {
            this.totalQuanlity =
                    new DecimalFormat(".00").format(ValueUtil.DoubleNullValue(
                            stringObjectMap.containsKey("total_quanlity") ? stringObjectMap.get("total_quanlity").toString() : ""
                    ));
        } catch (Exception ignored) {
        }
    }


}
